//
//  NewsIndexTableViewCell.m
//  YXFinance
//
//  Created by uplooking on 2018/10/23.
//  Copyright © 2018年 CRLong. All rights reserved.
//

#import "NewsIndexTableViewCell.h"

@interface NewsIndexTableViewCell()
{
    UIImageView * imageView;
    UILabel * labelTitle;
    UILabel * labelTime;
}
@end

@implementation NewsIndexTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self initView];
    }
    
    return self;
    
}

- (void)initView{
    
    
    imageView = [[UIImageView alloc]init];
    [imageView setUserInteractionEnabled:YES];
    [self addSubview:imageView];
    [imageView.layer setMasksToBounds:YES];
    [imageView.layer setCornerRadius:4.0 * kAutoScanleX];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self).inset(15 * kAutoScanleX);
        make.bottom.equalTo(self);
    }];
    
    UIImageView * blackImageView = [[UIImageView alloc]init];
    [imageView addSubview:blackImageView];
    [blackImageView setImage:[UIImage imageNamed:@"img_shipin_down_toumingbg"]];
    [blackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.left.equalTo(imageView);
        make.height.mas_equalTo(97/2.0 * kAutoScanleX);
    }];
    
    
    UIImageView * playImageView = [[UIImageView alloc]init];
    [imageView addSubview:playImageView];
    [playImageView setImage:[UIImage imageNamed:@"btn_play"]];
    [playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(imageView);
        make.size.mas_equalTo(CGSizeMake(50 * kAutoScanleX, 50 * kAutoScanleX));
    }];


    labelTitle = [[UILabel alloc]init];
    [labelTitle setTextColor:HexRGBA(0xffffff, 1)];
    [labelTitle setFont:[UIFont systemFontOfSize:16 * kAutoScanleX]];
    [labelTitle setTextAlignment:NSTextAlignmentLeft];
    [self addSubview:labelTitle];
    [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView).offset(15 * kAutoScanleX);
        make.top.equalTo(blackImageView);
        make.right.equalTo(imageView).offset(-15 * kAutoScanleX);
    }];
    
    
    labelTime = [[UILabel alloc]init];
    [labelTime setTextColor:HexRGBA(0xa4a4a4, 1)];
    [labelTime setFont:[UIFont systemFontOfSize:12 * kAutoScanleX]];
    [labelTime setTextAlignment:NSTextAlignmentLeft];
    [self addSubview:labelTime];
    [labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView).offset(15 * kAutoScanleX);
        make.top.equalTo(labelTitle.mas_bottom).offset(9 * kAutoScanleX);
        make.right.equalTo(imageView).offset(-15 * kAutoScanleX);
    }];
    
}

- (void)setModel:(NewsIndexModel *)model{
    
    [imageView sd_setImageWithURL:[NSURL URLWithString:model.litpic] placeholderImage:[UIImage imageNamed:@"bg_shpin_morentu"]];
    
    [labelTitle setText:model.title];
    
    [labelTime setText:model.addtime];
}

@end
